/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.coraci.anag.gui.components.basic.gui;

import it.coraci.anag.db.mongo.entities.Attribute;
import it.coraci.anag.gui.components.basic.gui.logic.CRUDParametrizablePanel;

/**
 *
 * @author Luca
 */
public class SimpleMultiParamPanel extends javax.swing.JPanel implements CRUDParametrizablePanel {

    private Attribute attribute;
    


    public SimpleMultiParamPanel(Attribute attribute, String [] values) {
        initComponents();
        this.attribute = attribute;
        this.jLabel1.setText(attribute.getKey());
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(values));
    }

//    public void setAttribute(Attribute attribute) {
//        this.attribute = attribute;
//        this.jLabel1.setText(attribute.getKey());
//    }

    public Attribute getAttribute() {
        attribute.setKey(this.jLabel1.getText());
        attribute.setValue(jComboBox1.getSelectedItem().toString());
        return attribute;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel1.setText("ParamKey:");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jComboBox1, 0, 133, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration//GEN-END:variables

    @Override
    public void setEditable(boolean editable) {
        this.jComboBox1.setEnabled(editable);

    }

    @Override
    public boolean isEditable() {
        return this.jComboBox1.isEnabled();
    }
    
    @Override
    public Object getValue() {
       return this.getAttribute().getValue();
    }

    @Override
    public void setValue(Object value) {
        this.jComboBox1.setSelectedItem(value);
        this.attribute.setValue(value.toString());
    }

    @Override
    public void clear() {
        attribute = null;
        this.jComboBox1.setModel(null);
    }
}
